/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ReportView.java
 *
 * Created on Feb 5, 2011, 6:51:31 AM
 */

package juwita;

/**
 *
 * @author Abah
 */
import java.sql.*;
import javax.swing.ImageIcon;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.swing.JRViewer;

public class ReportView extends javax.swing.JFrame {
    String rName = "-";

    /** Creates new form ReportView */
    public ReportView() {
        initComponents();
        this.setIconImage(new ImageIcon(getClass().getResource("/resource/3D.png")).getImage());
        System.out.println(rName);
        //showReport();
    }
    public ReportView(String r){
        initComponents();
        this.setIconImage(new ImageIcon(getClass().getResource("/resource/3D.png")).getImage());
        rName = r;
        System.out.println("rName : " + rName);
        showReport();
    }
    public ReportView(String r, String a, String b, String c, String d){
        initComponents();
        this.setIconImage(new ImageIcon(getClass().getResource("/resource/3D.png")).getImage());
        rName = r;
        System.out.println("rName : " + rName);
        showReport();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        scrollview = new javax.swing.JScrollPane();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));
        jPanel1.setLayout(new java.awt.BorderLayout());

        jLabel1.setBackground(new java.awt.Color(255, 255, 255));
        jLabel1.setText(" ");
        jPanel1.add(jLabel1, java.awt.BorderLayout.PAGE_START);
        jPanel1.add(scrollview, java.awt.BorderLayout.CENTER);

        getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);

        setBounds(0, 0, 408, 334);
    }// </editor-fold>//GEN-END:initComponents

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new ReportView().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane scrollview;
    // End of variables declaration//GEN-END:variables

    void showReport(){
        try{
            //param
            //Map<String, Object> params = new HashMap<String, Object>();
            //params.put("PRM_DETAIL_KDKATEGORI", "VID");

            String url="jdbc:mysql://localhost:3306/juwitamakmur";
            Class.forName("com.mysql.jdbc.Driver").newInstance();
            Connection conn = DriverManager.getConnection(url,"root","");
            
            System.out.println(rName);
            JasperReport report = JasperCompileManager.compileReport(rName);
            //with param
            //JasperPrint print = JasperFillManager.fillReport(report, params, conn);

            //no param
            JasperPrint print = JasperFillManager.fillReport(report, null, conn);

            JRViewer viewer = new JRViewer(print);
            viewer.setOpaque(true);
            viewer.setVisible(true);
            //add a scrollpane
            scrollview.add(viewer);
            scrollview.setViewportView(viewer);
            pack();

        }
        catch(Exception ex){
            ex.printStackTrace();
        }

    }

}
